package com.simple.common.entity.req.vm.pay;

import com.google.common.base.Preconditions;
import lombok.Data;

import javax.validation.constraints.Digits;
import javax.validation.constraints.NotBlank;
import java.util.Map;
import java.util.function.Consumer;

/**
 * @author yasud
 * @date 2020年10月10日 14:20
 * @description
 */
@Data
public class RefundTradeReq extends ReqBase {

    /**
     * 订单编号
     */
    @NotBlank(message = "订单标号不能为空")
    private String orderNo;

    /**
     * 退款金额
     */
    @NotBlank(message = "退款金额不能为空")
    @Digits(integer = 11, fraction = 2, message = "金额格式错误")
    private String refundAmount;

    /**
     * 退款原因
     */
    @NotBlank(message = "退款理由不能为空")
    private String refundReason;

    /**
     * 退款发起人
     */
    private String refundOriginator;

    /**
     * 拓展字段
     */
    private Map<String, Object> extra;


    @Override
    public void check(Consumer<ReqBase>... v) {
        Preconditions.checkState(getRefundAmount().indexOf(".") != -1, "订单金额必须以小数点后两位结束");
        String substring = getRefundAmount().substring(getRefundAmount().indexOf(".") + 1);
        Preconditions.checkState(substring.length() == 2, "订单金额必须以小数点后两位结束");
    }
}
